<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022-08-26
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
   <script src="statics/jquery-1.6.2.min.js"></script>
    <link href="${pageContext.request.contextPath}/statics/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<div style="margin: auto;text-align: center">
<table border="3" style="margin: 0 auto;border-collapse: collapse" class="layui-table">
    <colgroup>
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <tr style="text-align: center">
        <td>类别</td>
        <td>品种</td>
        <td>产地</td>
        <td>总重量（公斤）</td>
        <td>单价（元/公斤）</td>
        <td>采摘日期</td>
        <td>操作</td>
    </tr>
    <c:forEach var="fruit" items="${list}">
        <tr>
            <td>${fruit.type}</td>
            <td>${fruit.breed}</td>
            <td>${fruit.area}</td>
            <td>${fruit.weight}</td>
            <td>${fruit.price}</td>
            <td><fmt:formatDate value="${fruit.dataTime}" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
            <td>
                <a href="javascript:view(${fruit.fruitId})" class="layui-btn layui-btn-radius layui-btn-primary">查看</a>
                <a href="fruit/${fruit.fruitId}" class="layui-btn layui-btn-radius layui-btn-normal">详情</a>
                <a href="javascript:deleteFruit(${fruit.fruitId})" 	class="layui-btn layui-btn-radius layui-btn-danger">删除</a>
                <a href="add.jsp" class="layui-btn layui-btn-radius layui-btn-primary">新增</a>
            </td>
        </tr>
    </c:forEach>
</table>
</div>
<h1 align="center">水果详情</h1>
<div style="width: 30%;height: 20%;margin: auto">
    <table border="1" class="layui-table">
        <tr>
            <td>类别:</td>
            <td><span id="type"></span></td>
        </tr>
        <tr>
            <td>品种:</td>
            <td><span id="breed"></span></td>
        </tr>
        <tr>
            <td>产地:</td>
            <td><span id="area"></span></td>
        </tr>
        <tr>
            <td>简介:</td>
            <td><span id="brief"></span></td>
        </tr>
        <tr>
            <td>日期:</td>
            <td><span id="dataTime"></span></td>
        </tr>
        <tr>
            <td>图片:</td>
            <td><img src="${pageContext.request.contextPath}/statics/${requestScope.fruit.pic}"></td>
        </tr>
        <tr>
            <td colspan="2">
                <a href="javascript:history.back()" class="layui-btn layui-btn-radius layui-btn-primary">返回</a>
            </td>
        </tr>
    </table>
</div>
</body>
<script>
    function deleteFruit(id) {
        let  c=confirm('确定要删除吗');
        if (c){
            //
            $.get('delete','id='+id,function (data) {
                if (data=='success'){
                    alert("删除成功！")
                }else {
                    alert("删除失败")
                }
            })
            $.ajax({
                url:'fruit/'+id,
                type:'delete',
                dataType:"text",
                success:function (data) {
                    if (data=='success'){
                        alert("删除成功！")
                        location.reload();
                    }else {
                        alert("删除失败")
                    }
                }
            })
        }
    }

    function view(id) {
        $.get('view/'+id,function (data) {
            console.log(data);
            $('#type').html(data.type);
            $('#breed').html(data.breed);
            $('#area').html(data.area);
            $('#brief').html(data.brief);
            $('#dataTime').html(data.dataTime);
        },'json')
    }
</script>
</html>
